import com.alibaba.moco.*
import com.alibaba.dto.*
import com.alibaba.moco.util.*
import script.moco.dto.*;
import redis.clients.jedis.*
import groovy.json.*

//模拟司机确认到达上车地点
def excute(data){

	Jedis redis = RedisPoolInstance.getRedisClient();
	def params = data.getParameterMap();
    def request = BaseTypeUtil.mapToBean(params,DriverConfirmReachRequest.class) as DriverConfirmReachRequest;//请求数据转换为对象
    
    def response = new DriverConfirmReachResponse();							 								//定义响应对象
	
	def jsonStr = redis.get(request.getOrderId());																//从 Redis中获取 json 订单字符串	
		if(jsonStr==null){																						//验证订单是否存在
			response.setSuccess("false");
			response.setErrorMsg("订单id不存在 !");
			response.setErrorCode(39001);
			response.setErrorLevel(1);
			
			return response;
		}
		
		def slurper = new JsonSlurper();			
		def detailMap = slurper.parseText(jsonStr);
		System.out.println(jsonStr)
		if (!detailMap.containsKey("order")){
			response.setSuccess("false");
			response.setErrorMsg("订单不存在 !");
			response.setErrorCode(39001);
			response.setErrorLevel(1);
			
			return response;
		}															//从json字符串变成json对象	
		def jsonMap = detailMap.get("order");
		def taxiObj = BaseTypeUtil.jsonToBean(jsonMap,OrderInfo.class) as OrderInfo;						//将json对象转换为TaxiRequest对象
		
		//.司机确认到达上车地点完善数据
		taxiObj.setDlng(request.getDriverLongitude());
		taxiObj.setDlat(request.getDriverLatitude());
		//taxiObj.setDriverGeotype(request.getDriverGeotype());
		taxiObj.setStatus(410);
		taxiObj.setSub_status(4101);
		
		detailMap.put("order", taxiObj)
		redis.set(taxiObj.getId(), JsonOutput.toJson(detailMap).toString())	//直接覆盖原有数据，进行修改
		
		
		//司机确认到达上车地点完成后进行回调
		def callbackObj = new CallbackRequest();
			callbackObj.setClientId("1");
			callbackObj.setOrderId(taxiObj.getId());
			callbackObj.setNotifyType(1);
			callbackObj.setNotifyDesc("订单中间状态流转[司机到达]");
			callbackObj.setTimestamp(System.currentTimeMillis());
			callbackObj.setSign("123");
			
		HttpClientUtil.post(callbackObj);	
		
		response.setSuccess("true");
		response.setErrorMsg(null);
		response.setErrorCode(0);
		response.setErrorLevel(0);
		response.setContent(null);
		
    return response;
}